
var sf = require('./../../scripts/shared/helpers.js');

sf.extend(sf, require('./../../scripts/shared/options.js'));
sf.extend(sf, require('./options.js'));


var collector	= require('./collector')
,	processor	= require('./processor')
,	identify	= require('./identify')
,	builder		= require('./builder');


exports.Sauberfant = function (client) {
	this.client		= client;
	this.options	= sf.options;
};



exports.Sauberfant.prototype = {

	collect: function (req, res) {

		var self = this;

		identify.all(req, self.client, function (request) {
			collector.collect.call(self, req, res, self.client, request);
		});

	},

	process: function (req, res) {

		var self = this;

		identify.page(req, self.client, function (request) {
			processor.process.call(self, req, res, self.client, request);
		});

	},

	build: function (req, res) {
		builder.build.call(this);
	},

	overlay: function (req, res) {

		var self = this;

		identify.page(req, self.client, function (request) {

			var properties = {
				title: 'Overlay',
				location: request.page.loc,
				id: request.page.id,
				page: request.page
			};

			res.render('overlay.jade', properties);
		});
	}
};
